/// specified as well as the exe suffix
fn filename_parts(target: Option<&str>, cfg: &Config)
-> CargoResult<(Option<(String, String)>, String)> {
- let mut process = try!(util::process(cfg.rustc(), cfg.cwd()));
+ let mut process = util::process(cfg.rustc());
process.arg("-")
.arg("--crate-name").arg("_")
.arg("--crate-type").arg("dylib")
pub fn new(ty: CommandType, config: &Config)
-> CargoResult<CommandPrototype> {
Ok(CommandPrototype {
- builder: try!(match ty {
- CommandType::Rustc => process(config.rustc(), config.cwd()),
- CommandType::Rustdoc => process(config.rustdoc(), config.cwd()),
- CommandType::Target(ref s) |
- CommandType::Host(ref s) => process(s, config.cwd()),
- }),
+ builder: {
+ let mut p = match ty {
+ CommandType::Rustc => process(config.rustc()),
+ CommandType::Rustdoc => process(config.rustdoc()),
+ CommandType::Target(ref s) |
+ CommandType::Host(ref s) => process(s),
+ };
+ p.cwd(config.cwd());
+ p
+ },
ty: ty,
})
}
}
pub fn get_args(&self) -> &[OsString] { self.builder.get_args() }
- pub fn get_cwd(&self) -> &Path { self.builder.get_cwd() }
+ pub fn get_cwd(&self) -> Option<&Path> { self.builder.get_cwd() }
pub fn get_env(&self, var: &str) -> Option<OsString> {
self.builder.get_env(var)
use std::path::Path;
use std::process::{Command, Output};
-use util::{CargoResult, ProcessError, process_error};
+use util::{ProcessError, process_error};
use util::shell_escape::escape;
#[derive(Clone, PartialEq, Debug)]
program: OsString,
args: Vec<OsString>,
env: HashMap<String, Option<OsString>>,
- cwd: OsString,
+ cwd: Option<OsString>,
}
impl fmt::Display for ProcessBuilder {
}
pub fn cwd<T: AsRef<OsStr>>(&mut self, path: T) -> &mut ProcessBuilder {
- self.cwd = path.as_ref().to_os_string();
+ self.cwd = Some(path.as_ref().to_os_string());
self
}
pub fn get_args(&self) -> &[OsString] {
&self.args
}
- pub fn get_cwd(&self) -> &Path {
- Path::new(&self.cwd)
+
+ pub fn get_cwd(&self) -> Option<&Path> {
+ self.cwd.as_ref().map(Path::new)
}
pub fn get_env(&self, var: &str) -> Option<OsString> {
pub fn build_command(&self) -> Command {
let mut command = Command::new(&self.program);
- command.current_dir(&self.get_cwd());
+ if let Some(cwd) = self.get_cwd() {
+ command.current_dir(cwd);
+ }
for arg in self.args.iter() {
command.arg(arg);
}
}
}
-pub fn process<T: AsRef<OsStr>, U: AsRef<OsStr>>(cmd: T, cwd: U) -> CargoResult<ProcessBuilder> {
- Ok(ProcessBuilder {
+pub fn process<T: AsRef<OsStr>>(cmd: T) -> ProcessBuilder {
+ ProcessBuilder {
program: cmd.as_ref().to_os_string(),
args: Vec::new(),
- cwd: cwd.as_ref().to_os_string(),
+ cwd: None,
env: HashMap::new(),
- })
+ }
}
/// If successful this function returns a description of the compiler along
/// with a list of its capabilities.
pub fn new<P: AsRef<Path>>(path: P, cwd: &Path) -> CargoResult<Rustc> {
- let mut cmd = try!(util::process(path.as_ref(), cwd));
- cmd.arg("-vV");
+ let mut cmd = util::process(path.as_ref());
+ cmd.cwd(cwd).arg("-vV");
let mut ret = Rustc::blank();
let mut first = cmd.clone();
impl HgRepo {
pub fn init(path: &Path, cwd: &Path) -> CargoResult<HgRepo> {
- try!(try!(process("hg", cwd)).arg("init").arg(path).exec());
+ try!(process("hg").cwd(cwd).arg("init").arg(path).exec());
return Ok(HgRepo)
}
pub fn discover(path: &Path, cwd: &Path) -> CargoResult<HgRepo> {
- try!(try!(process("hg", cwd)).arg("root").cwd(path).exec_with_output());
+ try!(process("hg").cwd(cwd).arg("root").cwd(path).exec_with_output());
return Ok(HgRepo)
}
}